package com.rui.study.algorithm.T_OutOfMemoryError;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-02-25 11:17
 **/
public class JavaMethodArea {

    public static void main(String[] args) {
        while (true) {
            Foo foo = createBean(Foo.class);
        }
    }


    public static <T> T createBean(Class<T> klass) {
        Enhancer e = new Enhancer();
        e.setSuperclass(klass);
        e.setUseCache(false);
        e.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                System.out.println(">>intercept()<<");
                return proxy.invokeSuper(obj, args);
            }
        });
        return (T) e.create();
    }

}
